#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include<string.h>


void ecran()
{
int x,y;
    SDL_Surface *fenetre11;
    SDL_Surface *fenetre2;
    SDL_Surface *fenetre22;
        SDL_Surface *fenetre222;
    SDL_Surface *fenetre1;
    SDL_Surface *screen;
    SDL_Event event;
    int numfenetre ;
    int done=1;
    SDL_Rect src,dest;

    freopen("CON","w",stdout);
    freopen("CON","r",stdin);

    // initialize SDL video
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("Unable to init SDL: %s\n", SDL_GetError());
        return (-1);
    }
    // create a new window
    screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
    if (!screen)
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return (-1);
    }
    SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
    fenetre1 = SDL_LoadBMP("fenetre1.bmp");
    fenetre2= SDL_LoadBMP("fenetre2.bmp");
    fenetre11= SDL_LoadBMP("fenetre11.bmp");
    fenetre22= SDL_LoadBMP("fenetre22.bmp");
        fenetre222= SDL_LoadBMP("fenetre222.bmp");
    src.x = 0;
    src.y = 0;
    src.w = fenetre1->w; //Use image->w to display the entire width of the image
    src.h = fenetre1->h; //Use image->h to display the entire height of the image
    dest.x = 0;//
    dest.y = 0;
    dest.w = fenetre1->w;
    dest.h = fenetre1->h;
    SDL_BlitSurface(fenetre1, &src, screen, &dest);
    numfenetre=1;
    SDL_Flip(screen);
    while(done)
    {


        if (numfenetre==1)
        {
            x=event.motion.x;
            printf("%d",x);
            y=event.motion.y;
           if (x<424 && x>212 && y<425&&y>377)
            {
                SDL_BlitSurface(fenetre11, &src, screen, &dest);
                SDL_Flip(screen);
                numfenetre=11;

            }
            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;
                    break;









                }
                }
            }
        }
        if(numfenetre ==11)


        {
            x=event.motion.x;
            printf("%d",x);
            y=event.motion.y;
            if (x>424 || x<212 || y>425 || y<377)
            {
                SDL_BlitSurface(fenetre1, &src, screen, &dest);
                SDL_Flip(screen);
                numfenetre=1;

            }

            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;
                    break;

                    case SDL_MOUSEBUTTONDOWN:

                        if(x<424 && x>212&& y>377 && y<425)
                        {
                            SDL_BlitSurface(fenetre2, &src, screen, &dest);
                            SDL_Flip(screen);
                            numfenetre=2;

                        }











                    }
                }
            }







        }

        if (numfenetre==2)
        {
            x=event.motion.x;
            printf("%d",x);
            y=event.motion.y;
            if (x<561&&x>121&&y<267&&y>213)
            {
                SDL_BlitSurface(fenetre222, &src, screen, &dest);
                SDL_Flip(screen);
                numfenetre=222;
            }
            if (x>213&&x<430&&y<430&&y>381)
            {
                SDL_BlitSurface(fenetre22, &src, screen, &dest);
                SDL_Flip(screen);
                numfenetre=22;
            }


            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;
                    break;




                }
                }
            }
        }
         if(numfenetre ==22)


        {
            x=event.motion.x;
            printf("%d",x);
            y=event.motion.y;
              if (x<213||x>430||y>430||y<381)
            {
                SDL_BlitSurface(fenetre2, &src, screen, &dest);
                SDL_Flip(screen);
                numfenetre=2;
            }
            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;
                    break;

                    case SDL_MOUSEBUTTONDOWN:

                        if(x<424 && x>212&& y>377 && y<425)
                        {
                            SDL_BlitSurface(fenetre1, &src, screen, &dest);
                            SDL_Flip(screen);
                            numfenetre=1;

                        }











                    }
                }
            }







        }
if(numfenetre ==222)


        {
            x=event.motion.x;
            printf("%d",x);
            y=event.motion.y;

                        if(x>561 || x<121|| y<213 || y>267)
                            {SDL_BlitSurface(fenetre2, &src, screen, &dest);
                            SDL_Flip(screen);
                            numfenetre=2;

                        }


            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;
                    break;

                    case SDL_MOUSEBUTTONDOWN:

                        if(x<561 && x>121&& y>213 && y<267)
                        {
                             int ii=saisi(&numfenetre);
                        }











                    }
                }
            }







        }



    }}
